﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace MDS
{
    public class AggregatedQuotationProvider : IQuotationProvider
    {
      
        public event MultiMessageHandler<Protocol.IMessage> MessagesReceived;

        protected List<IQuotationProvider> _quotationProviders = new List<IQuotationProvider>();

        public AggregatedQuotationProvider(params IQuotationProvider[] QuotationProviders)
        {
            Contract.Requires(QuotationProviders.Any());
            foreach (var qp in QuotationProviders)
            {
                _quotationProviders.Add(qp);
            
                qp.MessagesReceived += new MultiMessageHandler<Protocol.IMessage>(qp_OnMessagesReceived);

            }
        }

        void qp_OnMessagesReceived(IEnumerable<Protocol.IMessage> messages)
        {
            MultiMessageHandler<Protocol.IMessage> handler = this.MessagesReceived;
            if (handler != null)
                handler(messages);
        }

     

        public void Start()
        {
            foreach (var qp in this._quotationProviders)
                qp.Start();
        }

        public void Stop()
        {
            foreach (var qp in this._quotationProviders)
                qp.Stop();
        }

        public void Clear()
        {
            foreach (var qp in this._quotationProviders)
                qp.Clear();
        }






    }
}
